﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Poem.Core.Entities;
using Poem.Core.Repositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace Poem.EF.Repositories
{
    public class CategoryPoemRepository : EfCoreRepository<PoemDbContext, CategoryPoem, int>, ICategoryPoemRepository
    {
        public CategoryPoemRepository(IDbContextProvider<PoemDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public List<Category> GetPoemCategories(int poemId)
        {
            var set = DbContext.Set<CategoryPoem>().Include(o => o.Category).AsQueryable();
            var list = set.Where(p => p.PoemId == poemId).Select(o => o.Category);
            return list.ToList();
        }

        public List<Core.Entities.Poem> GetPoemsOfCategory(int categoryId)
        {
            var set = DbContext.Set<CategoryPoem>().Include(o => o.Poem).AsQueryable();
            var list = set.Where(p => p.CategoryId == categoryId).Select(o => o.Poem);
            return list.ToList();
        }
    }
}
